<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Close anomaly detection jobs API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'ml-close-job.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/ml-close-job.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/ml-close-job.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/ml-close-job.html" rel="nofollow" target="_blank">../en/ml-close-job.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="ml-apis.html">Machine learning anomaly detection APIs</a></span>
»
<span class="breadcrumb-node">Close anomaly detection jobs API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="ml-put-calendar-job.html">« Add anomaly detection jobs to calendar API</a>
</span>
<span class="next">
<a href="ml-put-job.html">Create anomaly detection jobs API »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="ml-close-job"></a>Close anomaly detection jobs API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>

<p>Closes one or more anomaly detection jobs.
A job can be opened and closed multiple times throughout its lifecycle.</p>
<p>A closed job cannot receive data or perform analysis
operations, but you can still explore and navigate results.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-close-job-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">POST _ml/anomaly_detectors/&lt;job_id&gt;/_close</code><br></p>
<p><code class="literal">POST _ml/anomaly_detectors/&lt;job_id&gt;,&lt;job_id&gt;/_close</code><br></p>
<p><code class="literal">POST _ml/anomaly_detectors/_all/_close</code><br></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-close-job-prereqs"></a>Prerequisites<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
If the Elasticsearch security features are enabled, you must have <code class="literal">manage_ml</code> or
<code class="literal">manage</code> cluster privileges to use this API. See
<a class="xref" href="security-privileges.html" title="Security privileges">Security privileges</a>.
</li>
<li class="listitem">
Before you can close an anomaly detection job, you must stop its datafeed. See
<a class="xref" href="ml-stop-datafeed.html" title="Stop datafeeds API">Stop datafeeds</a>.
</li>
</ul>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-close-job-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a>
</h3>
</div></div></div>
<p>You can close multiple anomaly detection jobs in a single API request by using a group
name, a comma-separated list of jobs, or a wildcard expression. You can close
all jobs by using <code class="literal">_all</code> or by specifying <code class="literal">*</code> as the <code class="literal">&lt;job_id&gt;</code>.</p>
<p>When you close a job, it runs housekeeping tasks such as pruning the model history,
flushing buffers, calculating final results and persisting the model snapshots.
Depending upon the size of the job, it could take several minutes to close and
the equivalent time to re-open.</p>
<p>After it is closed, the job has a minimal overhead on the cluster except for
maintaining its meta data. Therefore it is a best practice to close jobs that
are no longer required to process data.</p>
<p>When a datafeed that has a specified end date stops, it automatically closes
the job.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>If you use the <code class="literal">force</code> query parameter, the request returns without performing
the associated actions such as flushing buffers and persisting the model snapshots.
Therefore, do not use this parameter if you want the job to be in a consistent state
after the close job API returns.  The <code class="literal">force</code> query parameter should only be used in
situations where the job has already failed, or where you are not interested in
results the job might have recently produced or might produce in the future.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-close-job-path-parms"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;job_id&gt;</code>
</span>
</dt>
<dd>
(Required, string)
Identifier for the anomaly detection job. It can be a job identifier, a group name, or a
wildcard expression.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-close-job-query-parms"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">allow_no_jobs</code>
</span>
</dt>
<dd>
<p>
(Optional, boolean)
Specifies what to do when the request:
</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Contains wildcard expressions and there are no jobs that match.
</li>
<li class="listitem">
Contains the <code class="literal">_all</code> string or no identifiers and there are no matches.
</li>
<li class="listitem">
Contains wildcard expressions and there are only partial matches.
</li>
</ul>
</div>
<p>The default value is <code class="literal">true</code>, which returns an empty <code class="literal">jobs</code> array
when there are no matches and the subset of results when there are partial
matches. If this parameter is <code class="literal">false</code>, the request returns a <code class="literal">404</code> status code
when there are no matches or only partial matches.</p>
</dd>
<dt>
<span class="term">
<code class="literal">force</code>
</span>
</dt>
<dd>
(Optional, boolean) Use to close a failed job, or to forcefully close a job
which has not responded to its initial close request.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Controls the time to wait until a job
has closed. The default value is 30 minutes.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-close-job-response-codes"></a>Response codes<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">404</code> (Missing resources)
</span>
</dt>
<dd>
If <code class="literal">allow_no_jobs</code> is <code class="literal">false</code>, this code indicates that there are no
resources that match the request or only partial matches for the request.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-close-job-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/close-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _ml/anomaly_detectors/low_request_rate/_close</pre>
</div>
<div class="console_widget" data-snippet="snippets/1798.console"></div>
<p>When the job is closed, you receive the following results:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "closed": true
}</pre>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="ml-put-calendar-job.html">« Add anomaly detection jobs to calendar API</a>
</span>
<span class="next">
<a href="ml-put-job.html">Create anomaly detection jobs API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>